#include "ScriptableVector.hpp"

ScriptableVector::ScriptableVector(){
}

/**
 * Get element at index i.
 * @param i Index of element to get.
 * @return Element at index i.
 */
Scriptable* ScriptableVector::at(int i){
    return vector.at(i);
}

/**
 * Get number of elements in vector.
 * @return Number of elements in vector.
 */
int ScriptableVector::size(){
    return vector.size();
}

/**
 * Remove element from the vector.
 * @param element Element to remove from vector.
 * @return true if element was removed, false if not found.
 */
bool ScriptableVector::remove(Scriptable* element){
    for(int i = 0; i < vector.size(); i++){
        if(vector.at(i) == element){
            vector.erase(vector.begin() + i);
            return true;
        }
    }
    return false;
}

void ScriptableVector::bind(lua_State* luaState){
    luabind::module(luaState)[
        luabind::class_<ScriptableVector>("Vector")
            .def("at", &ScriptableVector::at)
            .def("remove", &ScriptableVector::remove)
            .def("size", &ScriptableVector::size)
    ];
}

void ScriptableVector::push(lua_State* luaState){
    luabind::object o = luabind::object(luaState, this);
    o.push(luaState);
}